/*
APPENDIX TABLE 5
Share of Workers in Non-PSL Mandate Places Reporting Access to Paid Sick by Firm Exposure to Mandates, Predicted Values from Non-Linear Specification
*/

cd "$exhibits_path"

use "$data_path/main_analysis_file.dta", clear

*use "~/Harvard University/HKS_Shift - products/papers/Paid_Sick_Diffuse/data/sp21_harm_natl_imputed_weighted_c_psl_state_controls_final.dta", clear

	global demog i.gender i.race2_harm c.age_text_clean i.kids i.eslhome i.enrolled i.cohabstatus
	global work i.manager i.longwork_yrs i.union c.hourwage_clean c.usualhours_clean 
	global statechars c.unionmem_pc c.unemp_rate  c.minwage_state  	c.race_black c.race_amind c.race_asian c.race_pacisl c.race_other c.race_multi c.hispan c.age_u5 c.age_5to9 c.age_10to14 c.age_75to84 c.age_85plus c.female_pc c.educ_pc_hsgrad c.educ_pc_somecoll c.educ_pc_assoc c.educ_pc_bach c.educ_pc_grad

	global empchars i.shift_ind c.total_emps c.total_ests

*Creating variables to bin respondents by percentage of workers covered by Paid Sick mandates
gen bin_emps_psl_place = 1 if pct_emps_psl_place>=0  & pct_emps_psl_place <15
replace bin_emps_psl_place = 2 if pct_emps_psl_place>=15 & pct_emps_psl_place <30
replace bin_emps_psl_place = 3 if pct_emps_psl_place>=30 & pct_emps_psl_place <45
replace bin_emps_psl_place = 4 if pct_emps_psl_place>=45 & pct_emps_psl_place <=100

*Demographic controls only
eststo col7row3: mi est, post: reg benefits_paidsick i.bin_emps_psl_place $demog if  psl_law_places_hybd == 0, vce(cluster statelist) 

*Demographic and work controls 
eststo col8row3: mi est, post: reg benefits_paidsick i.bin_emps_psl_place $demog  $work if  psl_law_places_hybd == 0, vce(cluster statelist)  

*Demographic, work, and employer controls 
eststo col9row3: mi est, post: reg benefits_paidsick i.bin_emps_psl_place $demog  $work $empchars if  psl_law_places_hybd == 0, vce(cluster statelist)  
*Demographic, work, employer, and state characteristics controls
eststo col10row3: mi est, post: reg benefits_paidsick i.bin_emps_psl_place $demog  $work $empchars $statechars if  psl_law_places_hybd == 0, vce(cluster statelist)  

*Demographic, work, employer, state characteristics, and state fixed effects
eststo col11row3: mi est, post: reg benefits_paidsick i.bin_emps_psl_place $demog $work $empchars $statechars i.statelist if  psl_law_places_hybd == 0, vce(cluster statelist)  

*Demographic, work, employer, state characteristics, state fixed effects, and year fixed effects
eststo col12row3: mi est, post: reg benefits_paidsick i.bin_emps_psl_place $demog $work $statechars $empchars i.statelist i.year##i.month if  psl_law_places_hybd == 0, vce(cluster statelist)  

*local macros to display controls
estadd local DCchecka "\checkmark": col7row3 col8row3 col9row3 col10row3 col11row3 col12row3
estadd local WCchecka "\checkmark": col8row3 col9row3 col10row3 col11row3 col12row3
estadd local INDchecka "\checkmark": col9row3 col10row3 col11row3 col12row3
estadd local SCchecka "\checkmark": col10row3 col11row3 col12row3
estadd local STATEchecka  "\checkmark": col11row3 col12row3
estadd local YEARchecka "\checkmark":  col12row3

*Code to write latex table
esttab col7row3 col8row3 col9row3 col10row3 col11row3 col12row3 using "$exhibits_path/Appendix Table 5.tex", ///
	prehead("{\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi} \begin{tabular}{l*{6}{c}} \hline\hline") ///
	fragment keep(2.bin_emps_psl_place 3.bin_emps_psl_place 4.bin_emps_psl_place) ///
		coeflabel(2.bin_emps_psl_place "\hspace{0.5cm} 15-30\% of Workers Covered" 3.bin_emps_psl_place "\hspace{0.5cm} 30-45\% of Workers Covered" 4.bin_emps_psl_place "\hspace{0.5cm} 45\%+ of Workers Covered") ///
	 noomitted noconstant nonumbers nonote nodepvars mtitles("M1" "M2" "M3" "M4" "M5" "M6") ///
	 refcat(2.bin_emps_psl_place "\textit{Share in a PSL Covered State or County}", nolabel) ///
	 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) ///
	 	 mgroups("\shortstack{PSL Access in Non-Mandate Places} " , pattern(1 0 0 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) /// 
		postfoot("\hline\hline \multicolumn{7}{l}{\footnotesize \sym{+} \(p<0.10\), \sym{*} \(p<0.05\), \sym{**} \(p<0.01\), \sym{***} \(p<0.001\)}\\ \end{tabular} } ") ///
	eqlabels(none) noomitted noconstant not nonote noobs  nodepvars nonumbers label b(%9.3f) /// 
	scalars("DCchecka Demographic Controls" "WCchecka Work Controls" "INDchecka Firm Controls" "SCchecka State Controls" "STATEchecka State FE" "YEARchecka Year, Month, Year $\times$ Month FE"  "line \hline \vspace{-1em}" "N N") ///
	sfmt(%9.0f) ///
	prefoot("\vspace{0.1em} \\") ///
	replace